package com.doodle.common.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import java.lang.reflect.Field;
import java.util.List;

public class DeviceUtils {
	
	/**
	 * 
	 * @param deviceName 
	 * 			there is M9, MX, MX2 so far.
	 * @return
	 */
	public static boolean isFromDevice(String deviceName) {
	    try{
	    	String fullName = ("IS_" + deviceName).toUpperCase();
	    	Class<?> classType = Class.forName("android.os.Build");
	    	Field type = classType.getField(fullName);
	    	if ("true".equals(type.get(fullName).toString())) {
	    		return true;
	    	} else {
	    		return false;
	    	}
        } catch(Exception e){
            e.printStackTrace();
        }
	    return false;
	}
	
	public static boolean isIntentAvailable(Context context, Intent intent) {
	    final PackageManager packageManager = context.getPackageManager();
	    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
	    return list.size() > 0;
	}
}
